<?php
class Util{
	static function getEmbedVideoCode($url, $width = 640, $height = 385){
		$pos = strpos($url, "youtube");
		if($pos !== false){
			//Obtenemos el id del video
			preg_match("#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=v\/)[^&\n]+|(?<=v=)[^&\n]+|(?<=youtu.be/)[^&\n]+#", $url, $matches);
			$videoId = $matches[0];
			return '<iframe class="youtube-player" type="text/html" width="'.$width.'" height="'.$height.'" src="http://www.youtube.com/embed/'.$videoId.'" frameborder="0"></iframe>';
		}
		else{
			 preg_match('/^http:\/\/(www\.)?vimeo\.com\/(clip\:)?(\d+).*$/', $url, $matches);
			 echo '<iframe src="http://player.vimeo.com/video/'.$matches[3].'?title=0&amp;byline=0&amp;portrait=0" width="'.$width.'" height="'.$height.'" frameborder="0" webkitAllowFullScreen allowFullScreen></iframe>';
		}
	}
}